package com.example.task1.ui.AllService.movies;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.example.task1.R;
import com.example.task1.bean.MoniesFilmBean;
import com.example.task1.bean.MoviesHallBean;
import com.example.task1.ui.BaseAdapter;

import java.util.ArrayList;
import java.util.List;

public class MoviesHallAdapter extends BaseAdapter<MoviesHallBean.RowsDTO> {

    private Context context;
    private List<MoviesHallBean.RowsDTO> data = new ArrayList<>();
    private TextView tvStartTime;
    private TextView tvEndTime;
    private TextView tvHall;
    private TextView tvPrice;
    private Button btnSave;
    private int cinemaId;
    private int movieId;

    public MoviesHallAdapter(Context context) {
        this.context = context;
    }

    @Override
    protected void setData(List<MoviesHallBean.RowsDTO> rows) {
        int size = data.size();
        data.addAll(rows);
        notifyItemInserted(size);
    }

    protected void setData(List<MoviesHallBean.RowsDTO> rows, int cinemaId, int movieId) {
        data = rows;
        notifyDataSetChanged();
        this.cinemaId = cinemaId;
        this.movieId = movieId;
    }

    @Override
    protected int getLayout() {
        return R.layout.movieshalllist;
    }

    @Override
    protected Context getContext() {
        return context;
    }

    @Override
    protected List<MoviesHallBean.RowsDTO> getData() {
        return data;
    }

    @Override
    protected void onBind(myHolder holder, MoviesHallBean.RowsDTO date) {
        tvEndTime.setText(date.getEndTime() + "散场");
        tvStartTime.setText(date.getStartTime());
        tvHall.setText(date.getRoomName());
        tvPrice.setText(date.getPrice() + "￥");
        btnSave.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context,MoviesSeatActivity.class);
                intent.putExtra("id", cinemaId);
                intent.putExtra("ids", movieId);
                intent.putExtra("roomId", date.getId());
                intent.putExtra("roomIds", date.getRoomId());
                context.startActivity(intent);
            }
        });
    }

    @Override
    protected void holder(View itemView) {
        initView(itemView);
    }




    private void initView(View itemView) {
        tvStartTime = (TextView) itemView.findViewById(R.id.tv_startTime);
        tvEndTime = (TextView) itemView.findViewById(R.id.tv_endTime);
        tvHall = (TextView) itemView.findViewById(R.id.tv_hall);
        tvPrice = (TextView) itemView.findViewById(R.id.tv_price);
        btnSave = (Button) itemView.findViewById(R.id.btn_save);
    }
}
